#! /bin/sh

if test x"$1" != x ; then
	psrchive_cmd=$1
else
	psrchive_cmd=psrchive
fi

psrchive=`which $psrchive_cmd 2> /dev/null`

echo "Using $psrchive"

if test -z $psrchive; then

  echo
  echo "PSRCHIVE installation not found."
  echo "If installed, please ensure that psrchive executable is in PATH"
  echo "If not installed, please see http://psrchive.sourceforge.net"
  echo
  exit -1

fi

echo "Copying autoconf and automake tools from PSRCHIVE ..."

cp `$psrchive --aclocal`/* config/

sh config/formats.sh

if test ! -d resources/googletest/googletest; then
  echo Updating googletest submodule
  git submodule update --init --recursive
fi

echo "Running the GNU autotools.  Please be patient ..."

if autoreconf --install --force; then

  echo
  echo "Bootstrap complete.  You can now run the configure script."
  echo
  exit 0

else

  echo
  echo "An error occured while running the GNU autotools."
  echo "Please see http://psrchive.sourceforge.net/third/autotools"
  echo
  exit -1

fi

